import request from '@/axios';

export const getList = (current, size, params) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/list',
        method: 'get',
        params: {
            ...params,
            current,
            size,
        }
    })
}

export const prodList = (current, size, params) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/prod-list',
        method: 'get',
        params: {
            ...params,
            current,
            size,
        }
    })
}

export const selectChildBomPage = (current, size, params) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/selectChildBomPage',
        method: 'get',
        params: {
            ...params,
            current,
            size,
        }
    })
}



export const getDetail = (id) => {
  return request({
    url: '/api/blade-anwise/material/bom_list/detail',
    method: 'get',
    params: {
      id
    }
  })
}

export const remove = (id) => {
  return request({
    url: '/api/blade-anwise/material/bom_list/remove?id='+id,
    method: 'get'
  })
}

export const add = (row) => {
  return request({
    url: '/api/blade-anwise/material/bom_list/submit',
    method: 'post',
    data: row
  })
}

export const update = (row) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/submit',
        method: 'post',
        data: row
    })
}

export const copy = (row) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/copy',
        method: 'post',
        data: row
    })
}

export const checkBom = (nodeNo) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/checkBom',
        method: 'get',
        params: {
            nodeNo
        }
    })
}

export const getBomTree = (nodeNo) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/getBomTree',
        method: 'get',
        params: {
            nodeNo
        }
    })
}

export const getByNodeNo = (nodeNo) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/getByNodeNo',
        method: 'get',
        params: {
            nodeNo
        }
    })
}

export const addWorkList = (row) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/addWorkList',
        method: 'post',
        data: row
    })
}

export const addMaterial = (row) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/addMaterial',
        method: 'post',
        data: row
    })
}

export const checkBomChild = (nodeNo, addNode) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/checkBomChild?nodeNo='+nodeNo+"&addNode="+addNode,
        method: 'get',
    })
}

export const checkBomParent = (nodeNo, parentNo) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/checkBomParent?nodeNo='+nodeNo+'&parentNo='+parentNo,
        method: 'get',
    })
}

export const checkByCalc = (nodeNo) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/checkByCalc?nodeNo='+nodeNo,
        method: 'get',
    })
}

export const generateRemark = (nodeNo,unit,num) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/generateRemark?nodeNo='+nodeNo+'&unit='+unit+'&num='+num,
        method: 'get',
    })
}

export const workListSelect = (nodeNo) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/workListSelect?nodeNo='+nodeNo,
        method: 'get',
    })
}

export const calcBom = (params) => {
    return request({
        url: '/api/blade-anwise/material/bom_list/calcBom',
        method: 'post',
        data: params,
    })
}

export const importBomList = (file,  progressFuc) => {
    const form = new FormData();
    form.append("file", file);
    return request({
        headers:{'Content-Type':'multipart/form-data'},
        url: '/api/blade-anwise/material/bom_list/import-bom-list',
        method: 'post',
        data: form,
        onUploadProgress:function(progressEvent){
            if (progressFuc) {
                if (progressEvent.total > 0) {
                    progressEvent.percent = progressEvent.loaded / progressEvent.total * 100;
                }
                progressFuc(progressEvent)
            }
        }
    })
}



